package app.repositories.impl;

import javax.persistence.EntityManager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import app.models.Observacao;
import app.repositories.ObservacaoRepository;
import app.repositories.Repository;
import app.util.Constants;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class ObservacaoRepositoryImpl extends Repository<Observacao, Long> implements ObservacaoRepository{

	protected ObservacaoRepositoryImpl(EntityManager entityManager) {
		super(entityManager);
	}
	
	public Observacao findByUsuarioId (Integer idUsuario) {
		Criteria criteria = super.createCriteria();
		
		criteria.add(Restrictions.eq(Constants.USUARIO_ID, idUsuario));
		
		return (Observacao) criteria.uniqueResult();
	}

}
